<?php

  /**
   * Provides diagnostic to ensure security password.<br />
   * Simply store the password in private and call the Check() method to
   * validate the password or not.<br />
   *
   * @param string $password The tested password.
   *
   * @author Dany Mottier
   * @version 2.1
   *
   */
  class Cracker extends Base {

    /**
     * Store the password for further process.<br />
     * Don't work directly with it.
     */
    private $password = "";

    /**
     * Simply store the password in private and call the Check() method to
     * validate the password or not.<br />
     *
     * @param string $password The tested password.
     */
    public function __construct($password) {
      if (Validator::Validate($password, Validator::STRING)) {
        $this->password = $password;
        $this->_Check();
      }
    }

    /**
     * Performs an obscure check with the given password.<br />
     * @see <a href="http://be.php.net/manual/en/function.crack-check.php">crack_check()</a>
     */
    private function _Check() {
      crack_check($this->password);
    }

    /**
     * Return the password used for the check.<br />
     * @return string The password as a string.
     */
    public function getPassword() {
      return $this->password;
    }

    /**
     * Returns the message from the last obscure check.<br />
     *
     * @exception Warning This function is EXPERIMENTAL. The behaviour of this
     * function, its name, and surrounding documentation may change without
     * notice in a future release of PHP. This function should be used at your
     * own risk.
     *
     * @return string The message from the last obscure check or FALSE if there
     * was no obscure checks made so far.<br />
     * The returned message is one of these :
     * "it's WAY too short",<br /> "it is too short",<br /> "it does not contain enough
     * DIFFERENT characters",<br /> "it is all whitespace",<br /> "it is too
     * simplistic/systematic",<br /> "it looks like a National Insurance number.",<br />
     * "it is based on a dictionary word",<br /> "it is based on a (reversed)
     * dictionary word" or "strong password"<br /><br />
     */
    public function getDiagnostic() {
      return crack_getlastmessage();
    }

  }

?>
